package com.bytedance.common.plugin.component;

import android.annotation.TargetApi;
import android.content.ContentProvider;
import android.content.ContentProviderResult;
import android.content.ContentValues;
import android.content.Context;
import android.content.OperationApplicationException;
import android.content.pm.ProviderInfo;
import android.content.res.AssetFileDescriptor;
import android.content.res.Configuration;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.os.CancellationSignal;
import android.os.ParcelFileDescriptor;

import com.bytedance.common.plugin.framework.PluginManager;

import java.io.FileDescriptor;
import java.io.FileNotFoundException;
import java.io.PrintWriter;
import java.util.ArrayList;

public class BaseProxyProvider extends ContentProvider {
    private ContentProvider mPluginProvider;

    public BaseProxyProvider() {

    }

    public ContentProviderResult[] applyBatch(ArrayList arg2) throws OperationApplicationException {
        ContentProviderResult[] v0 = this.mPluginProvider != null ? this.mPluginProvider.applyBatch(arg2) : super.applyBatch(arg2);
        return v0;
    }

    public void attachInfo(Context arg2, ProviderInfo arg3) {
        super.attachInfo(arg2, arg3);
        if(this.mPluginProvider != null) {
            this.mPluginProvider.attachInfo(arg2, arg3);
        }
    }

    public int bulkInsert(Uri arg2, ContentValues[] arg3) {
        int v0 = this.mPluginProvider != null ? this.mPluginProvider.bulkInsert(arg2, arg3) : super.bulkInsert(arg2, arg3);
        return v0;
    }

    @TargetApi(value=11) public Bundle call(String arg2, String arg3, Bundle arg4) {
        Bundle v0 = this.mPluginProvider != null ? this.mPluginProvider.call(arg2, arg3, arg4) : super.call(arg2, arg3, arg4);
        return v0;
    }

    @TargetApi(value=19) public Uri canonicalize(Uri arg2) {
        Uri v0 = this.mPluginProvider != null ? this.mPluginProvider.canonicalize(arg2) : super.canonicalize(arg2);
        return v0;
    }

    public int delete(Uri arg2, String arg3, String[] arg4) {
        int v0 = this.mPluginProvider != null ? this.mPluginProvider.delete(arg2, arg3, arg4) : 0;
        return v0;
    }

    @TargetApi(value=18) public void dump(FileDescriptor arg2, PrintWriter arg3, String[] arg4) {
        super.dump(arg2, arg3, arg4);
        if(this.mPluginProvider != null) {
            this.mPluginProvider.dump(arg2, arg3, arg4);
        }
    }

    protected String getPluginClass() {
        return com.bytedance.common.plugin.a.a.get(this.getClass().getName());
    }

    @TargetApi(value=11) public String[] getStreamTypes(Uri arg2, String arg3) {
        String[] v0 = this.mPluginProvider != null ? this.mPluginProvider.getStreamTypes(arg2, arg3) : super.getStreamTypes(arg2, arg3);
        return v0;
    }

    public String getType(Uri arg2) {
        String v0 = this.mPluginProvider != null ? this.getType(arg2) : null;
        return v0;
    }

    public Uri insert(Uri arg2, ContentValues arg3) {
        Uri v0 = this.mPluginProvider != null ? this.insert(arg2, arg3) : null;
        return v0;
    }

    public void onConfigurationChanged(Configuration arg2) {
        super.onConfigurationChanged(arg2);
        if(this.mPluginProvider != null) {
            this.mPluginProvider.onConfigurationChanged(arg2);
        }
    }

    public boolean onCreate() {
        this.tryLoadPlugin();
        boolean v0 = this.mPluginProvider != null ? this.mPluginProvider.onCreate() : false;
        return v0;
    }

    public void onLowMemory() {
        super.onLowMemory();
        if(this.mPluginProvider != null) {
            this.mPluginProvider.onLowMemory();
        }
    }

    @TargetApi(value=14) public void onTrimMemory(int arg2) {
        super.onTrimMemory(arg2);
        if(this.mPluginProvider != null) {
            this.mPluginProvider.onTrimMemory(arg2);
        }
    }

    public AssetFileDescriptor openAssetFile(Uri arg2, String arg3) throws FileNotFoundException {
        AssetFileDescriptor v0 = this.mPluginProvider != null ? this.mPluginProvider.openAssetFile(arg2, arg3) : super.openAssetFile(arg2, arg3);
        return v0;
    }

    @TargetApi(value=19) public AssetFileDescriptor openAssetFile(Uri arg2, String arg3, CancellationSignal arg4) throws FileNotFoundException {
        AssetFileDescriptor v0 = this.mPluginProvider != null ? this.mPluginProvider.openAssetFile(arg2, arg3, arg4) : super.openAssetFile(arg2, arg3, arg4);
        return v0;
    }

    public ParcelFileDescriptor openFile(Uri arg2, String arg3) throws FileNotFoundException {
        ParcelFileDescriptor v0 = this.mPluginProvider != null ? this.mPluginProvider.openFile(arg2, arg3) : super.openFile(arg2, arg3);
        return v0;
    }

    @TargetApi(value=19) public ParcelFileDescriptor openFile(Uri arg2, String arg3, CancellationSignal arg4) throws FileNotFoundException {
        ParcelFileDescriptor v0 = this.mPluginProvider != null ? this.mPluginProvider.openFile(arg2, arg3, arg4) : super.openFile(arg2, arg3, arg4);
        return v0;
    }

    @TargetApi(value=11) public ParcelFileDescriptor openPipeHelper(Uri arg7, String arg8, Bundle arg9, Object arg10, ContentProvider.PipeDataWriter arg11) throws FileNotFoundException {
        ParcelFileDescriptor v0 = this.mPluginProvider != null ? this.mPluginProvider.openPipeHelper(arg7, arg8, arg9, arg10, arg11) : super.openPipeHelper(arg7, arg8, arg9, arg10, arg11);
        return v0;
    }

    @TargetApi(value=11) public AssetFileDescriptor openTypedAssetFile(Uri arg2, String arg3, Bundle arg4) throws FileNotFoundException {
        AssetFileDescriptor v0 = this.mPluginProvider != null ? this.mPluginProvider.openTypedAssetFile(arg2, arg3, arg4) : super.openTypedAssetFile(arg2, arg3, arg4);
        return v0;
    }

    @TargetApi(value=19) public AssetFileDescriptor openTypedAssetFile(Uri arg2, String arg3, Bundle arg4, CancellationSignal arg5) throws FileNotFoundException {
        AssetFileDescriptor v0 = this.mPluginProvider != null ? this.mPluginProvider.openTypedAssetFile(arg2, arg3, arg4, arg5) : super.openTypedAssetFile(arg2, arg3, arg4, arg5);
        return v0;
    }

    public Cursor query(Uri arg7, String[] arg8, String arg9, String[] arg10, String arg11) {
        Cursor v0 = this.mPluginProvider != null ? this.mPluginProvider.query(arg7, arg8, arg9, arg10, arg11) : null;
        return v0;
    }

    @TargetApi(value=16) public Cursor query(Uri arg8, String[] arg9, String arg10, String[] arg11, String arg12, CancellationSignal arg13) {
        Cursor v0 = this.mPluginProvider != null ? this.mPluginProvider.query(arg8, arg9, arg10, arg11, arg12, arg13) : super.query(arg8, arg9, arg10, arg11, arg12, arg13);
        return v0;
    }

    @TargetApi(value=11) public void shutdown() {
        super.shutdown();
        if(this.mPluginProvider != null) {
            this.mPluginProvider.shutdown();
        }
    }

    private void tryLoadPlugin() {
        if(this.mPluginProvider == null) {
            PluginManager.getPluginManager();
            this.mPluginProvider = ComponentHelper.loadPluginProvider(PluginManager.getHostClassLoader(), this.getPluginClass());
        }
    }

    @TargetApi(value=19) public Uri uncanonicalize(Uri arg2) {
        Uri v0 = this.mPluginProvider != null ? this.mPluginProvider.uncanonicalize(arg2) : super.uncanonicalize(arg2);
        return v0;
    }

    public int update(Uri arg2, ContentValues arg3, String arg4, String[] arg5) {
        int v0 = this.mPluginProvider != null ? this.mPluginProvider.update(arg2, arg3, arg4, arg5) : 0;
        return v0;
    }
}

